<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="标签名称" prop="labelName">
        <el-input
          v-model="queryParams.labelName"
          placeholder="请输入标签名称"
          clearable
          size="small"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标签颜色" prop="labelColor">
        <el-input
          v-model="queryParams.labelColor"
          placeholder="请输入标签颜色"
          clearable
          size="small"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input
          v-model="queryParams.sort"
          placeholder="请输入排序"
          clearable
          size="small"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-Plus" size="mini" @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          >导出</el-button
        >
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="event_labelList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="100">
        <template v-slot="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="标签名称" align="center" prop="labelName" />
      <el-table-column label="标签颜色" align="center" prop="labelColor">
        <template v-slot="scope">
          <!-- <div>{{ scope.row.labelColor }}</div> -->
          <div
            style="background: rgba(255, 0, 0, 1); width: 30px; height: 20px; margin: 0 auto"
            v-show="scope.row.labelColor === 'rgba(255, 0, 0, 1)'"
          ></div>
          <div
            style="background: rgba(255, 165, 0, 1); width: 30px; height: 20px; margin: 0 auto"
            v-show="scope.row.labelColor === 'rgba(255, 165, 0, 1)'"
          ></div>
          <div
            style="background: rgba(255, 255, 0, 1); width: 30px; height: 20px; margin: 0 auto"
            v-show="scope.row.labelColor === 'rgba(255, 255, 0, 1)'"
          ></div>
          <div
            style="background: rgba(0, 0, 255, 1); width: 30px; height: 20px; margin: 0 auto"
            v-show="scope.row.labelColor === 'rgba(0, 0, 255, 1)'"
          ></div>
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" prop="sort" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
      <template v-slot:empty>
        <el-empty :image-size="300"></el-empty>
      </template>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改事件标签对话框 -->
    <el-dialog :title="title" v-model:visible="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="标签名称" prop="labelName">
          <el-input v-model="form.labelName" placeholder="请输入标签名称" />
        </el-form-item>
        <el-form-item label="标签颜色" prop="labelColor">
          <el-color-picker v-model="form.labelColor" show-alpha :predefine="predefineColors">
          </el-color-picker>
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
  // import {
  //   listEvent_label,
  //   getEvent_label,
  //   delEvent_label,
  //   addEvent_label,
  //   updateEvent_label,
  // } from '../../../api/ywtg/eventLabel';

  const ids = ref([]);
  const open = ref(false);
  const loading = ref(false);
  const single = ref(true);
  const multiple = ref(true);
  const showSearch = ref(true);
  const title = ref('');
  const predefineColors = ref([
    'rgba(255, 0, 0, 1)',
    'rgba(255, 165, 0, 1)',
    'rgba(255, 255, 0, 1)',
    'rgba(0, 0, 255, 1)',
  ]);
  const total = ref(0);
  const event_labelList = ref([
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-03-12 10:39:41',
      updateBy: null,
      updateTime: '2024-03-12 11:46:47',
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 2,
      labelName: '测试1',
      labelColor: 'rgba(0, 0, 255, 1)',
      sort: 1,
    },
    {
      searchValue: null,
      gridId: null,
      gridName: null,
      gridDept: null,
      gridIds: null,
      gridIdsString: null,
      createBy: null,
      createTime: '2024-03-12 10:39:57',
      updateBy: null,
      updateTime: '2024-03-12 11:07:52',
      remark: null,
      poi: null,
      delFlag: null,
      params: {},
      id: 3,
      labelName: '测试2',
      labelColor: 'rgba(255, 165, 0, 1)',
      sort: 2,
    },
  ]);
  const queryParams = ref({
    pageNum: 1,
    pageSize: 10,
    labelName: null,
    labelColor: null,
    sort: null,
  });
  const form = ref({
    labelColor: '',
  });
  const rules = ref({});
</script>

<style lang="scss" scoped>
  .app-container {
    box-sizing: border-box;
    padding: 20px;
    overflow: auto;
  }
  .mb8 {
    margin-bottom: 8px;
  }
</style>
